package pe.com.bn.sach.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.ibatis.sqlmap.client.SqlMapClient;


import pe.com.bn.sach.dao.UbigeoDAO;
import pe.com.bn.sach.domain.Bnchf11Nacionalidad;
import pe.com.bn.sach.domain.Bnchf08Ubigeo;
public class UbigeoImpl implements UbigeoDAO {
	private static Logger log = Logger.getLogger(UbigeoImpl.class.getName());
	
	protected SqlMapClient sqlMap = null;
	
	public void setSqlMap(SqlMapClient sqlMap) {
		this.sqlMap = sqlMap;
	}

	public List listNacionalidad(Bnchf11Nacionalidad bnchf11Nacionalidad) throws Exception{
		return sqlMap.queryForList("sqlUbigeo.listaNacionalidad",bnchf11Nacionalidad);
	}
	
	public List getDatosUbigeo(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{

	List l = sqlMap.queryForList("sqlUbigeo.ubigeo",bnchf08Ubigeo);

	return l;
	}
	
	//Departamento
	
	public List listDepartamento(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{
		List l = sqlMap.queryForList("sqlUbigeo.departamento",bnchf08Ubigeo);
		return l;
	}
	
	//Provincia
	
	public List listProvincia(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{
		List l = sqlMap.queryForList("sqlUbigeo.provincia",bnchf08Ubigeo);
		return l;
	}
	
	//Distrito
	
	public List listDistrito(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{
		List l = sqlMap.queryForList("sqlUbigeo.distrito",bnchf08Ubigeo);
		return l;
	}
	
	
	
	public List listUbigeoDepartamento() throws Exception{    
		return sqlMap.queryForList("sqlUbigeo.listaDepartamento","");
	}
	
	public List listUbigeoProvincia(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{    
		return sqlMap.queryForList("sqlUbigeo.listaProvincia",bnchf08Ubigeo);
	}
	 
	public List listUbigeoDistrito(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{    
		return sqlMap.queryForList("sqlUbigeo.listaDistrito",bnchf08Ubigeo);
	}
	
	public Bnchf08Ubigeo encontrarDistrito(Bnchf08Ubigeo bnchf08Ubigeo) throws Exception{
		 try {
	    	bnchf08Ubigeo=(Bnchf08Ubigeo)sqlMap.queryForList("sqlUbigeo.encontrarDistrito",bnchf08Ubigeo).get(0);
	    	return bnchf08Ubigeo;
		} catch (Exception e) {
			bnchf08Ubigeo=new Bnchf08Ubigeo();
			bnchf08Ubigeo.setF08DescDpto("--.--"); 
			return bnchf08Ubigeo;
		}
	}
	
	
	

}
